import pymysql


conn = pymysql.connect(host = 'localhost', user='root',password='root',database='test2.db',charset='utf8')#建立表格
cur = conn.cursor()
cur.execute('create table if not exists student(number INTEGER PRIMARY KEY UNIQUE ,name TEXT,score FLOAT )')

#插入
print('创建成功')
date =[('20193323','王二小','99'),('528028','王大小','99')]
sql = "insert into student(number,name,score) values(%s,%s,%s)"
cur.executemany(sql,date)
cur.execute('select * from student')
print(cur.fetchall())
cur.execute('update student set score = 100 where number = 20193323')#修改
cur.execute('select * from student')#读取
print(cur.fetchall())
cur.execute('delete from student where number = 123')
cur.execute('select * from student')
print(cur.fetchall())
conn.commit()
cur.close()
conn.close()

